 <%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ include file="/WEB-INF/views/shared/taglib.jsp"%>
<%
	request.setAttribute("title", "我的海报");
%>
<%@ include file="/WEB-INF/views/shared/master/weContentHeader.jsp"%>
<style type="text/css">	
	body{
		background-image: url("<c:url value='/images/we/invitationIndex/bg1.jpg' />");
	}
	
	.bottom-lab {
		position: fixed;
		bottom: 0;
		background: #fff;
		width: 100%;
		text-align: center;
		font-weight: 700;
	}
	.bottom-lab>div {
		margin-bottom: 15px;
	}
	.swiper-container{
		padding-bottom:1rem;
	}
	.swiper-pagination-bullet-active{
		background:white;
	}
</style>
<input type="hidden" value="${qrCustomer.linkname}" id="refLinkname" />

<c:if test="${t_shareCode eq '' || t_shareCode==null}">
	<div class="goback" data-back-href="<c:url value='/wechat/cust/invitation/invitationIndex'/>"></div>
	<div style="margin:2.5rem;">
		<div class="swiper-container">
			 <div class="swiper-wrapper father">
			 	<c:forEach var="i" begin="4" end="6" step="1">
				 	<div class="swiper-slide ">
				 		<img style="width:100%;" src="<c:url value='/wechat/cust/invitation/qrCode?logo=0&content=${qrUrl}&picPath=${i}.jpg'/>" data-path="${i}.jpg" class="qrcode"/>
				 	</div>
			 	</c:forEach>
			</div>
			<div class="swiper-pagination" style="text-align: center;bottom:0px;"></div>
		</div>
	</div>
</c:if>
<c:if test="${t_shareCode ne '' && t_shareCode!=null}">
	<div style="text-align:center;">
		<img src="<c:url value='/wechat/cust/invitation/qrCode?logo=0&content=${qrUrl}&picPath=${posterUrl}'/>" style="width:80%;margin:1.0rem;"/>
	</div>
</c:if>
	
<%@ include file="/WEB-INF/views/shared/scripts/jquery.jsp"%>
<%@ include file="/WEB-INF/views/shared/scripts/jqweui.jsp"%>
<%@ include file="/WEB-INF/views/shared/scripts/tabmob.jsp"%>
<%@ include file="/WEB-INF/views/shared/scripts/swiper.jsp"%>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>

<script type="text/javascript">
	var winHeight = window.innerHeight-90;
	
	/*替换url地址里面的参数*/
	function changeURLArg(url,arg,arg_val){ 
	    var pattern=arg+'=([^&]*)'; 
	    var replaceText=arg+'='+arg_val; 
	    if(url.match(pattern)){ 
	        var tmp='/('+ arg+'=)([^&]*)/gi'; 
	        tmp=url.replace(eval(tmp),replaceText); 
	        return tmp; 
	    }else{ 
	        if(url.match('[\?]')){ 
	            return url+'&'+replaceText; 
	        }else{ 
	            return url+'?'+replaceText; 
	        } 
	    } 
	    return url+'\n'+arg+'\n'+arg_val; 
	} 
	
	function friend(linkHref,username){
		wx.onMenuShareAppMessage({
		    title: username+'的邀请海报',
		    desc:  username+'邀请您加入普天永利，开启创富之旅。',
		    link:  linkHref,
		    imgUrl: 'http://www.putiyoli.net/ares/images/logo.png',
		    success: function () {
		    	
		    },error:function(){
		    }
		});

		wx.onMenuShareTimeline({
			title: username+'邀请您加入普天永利，开启创富之旅。',
			link: linkHref,
		    imgUrl: 'http://www.putiyoli.net/ares/images/logo.png',
			success: function (res) {
			}
		});
	}
$(function(){
	var posterUrl="1.jpg";
	var shareCode = $.getUrlParam('shareCode');
	var userIdentity="${userIdentity}";
	
	var url=$.getVirtualPath()+"/wechat/cust/personCenter/shareSignature";
	var linkHref=location.href.split('#')[0];
	
	var href=encodeURIComponent(linkHref);

	var shareCodeParam=$.isNull(shareCode)?"":"&shareCode="+shareCode;
	var resultJson=$.getJsonPost(url,"href="+href+shareCodeParam);

	var username=$("#refLinkname").val();
	
	if($.isNull(shareCode)){
		linkHref=linkHref.appendUrlParam("shareCode="+userIdentity);
		linkHref=linkHref.appendUrlParam("posterUrl="+posterUrl);
	}
	if($.isNull(username)){
		username=resultJson.customer.linkname;
	}
	
	$(".swiper-container").swiper({
		pagination: '.swiper-pagination',
	    paginationClickable: true,
		autoplay:false,	
		onSlideChangeEnd:function(swiper){
			posterUrl = $(".swiper-slide-active img.qrcode").data("path");
			linkHref=changeURLArg(linkHref,'posterUrl',posterUrl);
			friend(linkHref,username);
		}
	});

	var config={
			debug: false,
		  	appId: resultJson.jsapiSignature.appId,// 公众号的唯一标识
		  	timestamp: resultJson.jsapiSignature.timestamp,// 生成签名的时间戳
		  	nonceStr: resultJson.jsapiSignature.nonceStr,// 生成签名的随机串
		  	signature: resultJson.jsapiSignature.signature,// 签名
		  	jsApiList: ['onMenuShareAppMessage','onMenuShareTimeline']
		}
	
	wx.config(config);
	
	
	// 微信事件
	wx.ready(function () {
		// 分享朋友
			friend(linkHref,username);

		// 微信错误处理机制
		wx.error(function (res) {
			console.log(res.errMsg);
		});
		
		
	});
	
});

</script>
<%@ include file="/WEB-INF/views/shared/master/weContentFooter.jsp"%>